<template>
  <div class="app-container">
    <!-- 品类筛选 -->
    <el-form ref="listFilterRef" :model="list.filter" inline>
      <el-form-item prop="parentId">
        <CategorySelect
          v-model="list.filter.parentId"
          placeholder="所属品类"
          :maxLevel="1"
        />
      </el-form-item>
      <el-form-item prop="name">
        <el-input v-model="list.filter.name" placeholder="品类名称" clearable />
      </el-form-item>
      <el-form-item prop="status">
        <status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <span>
        <AuthButton @click="c" name="新增" />
        <ExportExcel
          url="/sot-admin-api/product/category/downloadReportList"
          name="导出"
          :param="list.filter"
        />
      </span>
      <!-- <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      /> -->
    </div>

    <!-- 分页列表 -->
    <el-table
      v-loading="list.loading"
      :data="list.data"
      row-key="id"
      border
      fit
    >
      <el-table-column label="品类级别" prop="levelName">
        <template slot-scope="{ row }">
          <span style="user-select: none;">{{ row.levelName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="后端品类名称" prop="categoryName" />
      <el-table-column label="同级排序序号" prop="sort" />
      <el-table-column label="启用状态" width="120">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <!-- 品类编辑弹窗 -->
    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item
          v-if="form.data.level != 1"
          label="所属品类"
          prop="parentId"
          verify
        >
          <categorySelect v-model="form.data.parentId" :maxLevel="1" />
        </el-form-item>
        <el-form-item
          label="品类名称"
          prop="categoryName"
          :verify="{ maxLength: 7 }"
        >
          <el-input
            v-model="form.data.categoryName"
            placeholder="请输入品类名称"
          />
        </el-form-item>
        <el-form-item
          label="品类图标"
          prop="logo"
          v-if="form.data.level===1"
        >
          <Imgpond
            v-model="form.data.logo"
            :count="1"
            aspectRatio="1/1"
          />
        </el-form-item>
        <el-form-item label="序号" prop="sort" verify>
          <Sort v-model="form.data.sort" />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'
import CategorySelect from '@/components/CategorySelect/index.vue'

export default {
  mixins: [pageMixin],
  components: { CategorySelect },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/product/category',
      axiosConfig: {
        getList: {
          url: 'queryCategoryTree'
        },
        updateStatus: {
          url: 'changeStatus'
        },
        r: {
          url: 'selectOne'
        }
      },
      list: {
        dataAt: 'data.children',
        filter: {
          name: '',
          status: '',
          parentId: ''
        }
      }
    }),
  data () {
    return {
      categoryTree: []
    }
  }
}
</script>

<style lang="scss" scoped>
:deep(.el-table__body) {
  .el-table__expand-icon {
    position: relative;
    bottom: -2px;
    font-size: 18px;
    margin-right: 10px;
    .el-icon-arrow-right {
      font-weight: 600;
    }
  }
  .el-table__row--level-0 {
    td.el-table__cell {
      background: -webkit-linear-gradient(
        top,
        #fdfdfd,
        #f2f2f2,
        #fdfdfd
      ) !important;
    }
  }
  .el-table__row--level-1 {
    .cell {
      padding-left: 30px;
    }
  }
}
</style>
